import Vue from 'vue'
// import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue'
import router from './router/index.js'
import store from './store/store'
import './assets/css/reset.css';
import "./assets/less/RedRose.less";
import "./assets/less/GreenRose.less";

Vue.prototype.$echarts = echarts;
// import websocket from "./API/websocket";//找到封装的socket.js文件
// Vue.prototype.$websocket = websocket;//将其挂在原型上，这样 $websocket就在所有的 Vue 实例中可用了。

Vue.prototype.$axios = axios;
// eslint-disable-next-line no-console
import {
  Pagination,
  Dialog,
  Autocomplete,
  MessageBox,
  Table,
  TableColumn,
  Input,
  Collapse,
  CollapseItem,
  Switch,
  Drawer,
  Form,
  FormItem,
  Radio,
  RadioGroup,
  InputNumber,
  RadioButton,
  Select,
  Option,
  PageHeader,
  Header,
  Main,
  Container,
  Tabs,
  TabPane,
  Carousel,
  Cascader,
  CarouselItem,
  Tooltip,
  Button,
  DatePicker,
  Popover,
  Scrollbar,
  Checkbox,
  Loading,
  Message,
  Upload,
  InfiniteScroll,
  Badge,
  Image
} from 'element-ui'
Vue.use(Button);
Vue.use(Badge);
Vue.use(Collapse);
Vue.use(CollapseItem);
Vue.use(Cascader);
Vue.use(Carousel);
Vue.use(CarouselItem);
Vue.use(Container);
Vue.use(Checkbox);
Vue.use(DatePicker);
Vue.use(Dialog)
Vue.use(Drawer)
Vue.use(Form);
Vue.use(FormItem);
Vue.use(Radio);
Vue.use(RadioGroup);
Vue.use(RadioButton);
Vue.use(Image);
Vue.use(InputNumber);
Vue.use(InfiniteScroll);
Vue.use(Input)
Vue.use(Switch);
Vue.use(Select);
Vue.use(Option);
Vue.use(Pagination);
Vue.use(PageHeader);
Vue.use(Header);
Vue.use(Main);
Vue.use(Table);
Vue.use(TableColumn);
Vue.use(Tabs);
Vue.use(TabPane);
Vue.use(Tooltip);
Vue.use(Popover);
Vue.use(Scrollbar);
Vue.use(Upload);



Vue.use(Autocomplete)
Vue.use(Loading.directive);
Vue.prototype.$loading = Loading.service;
Vue.prototype.$msgbox = MessageBox;
Vue.prototype.$alert = Vue.prototype.$msgbox.alert;
Vue.prototype.$confirm = Vue.prototype.$msgbox.confirm
Vue.prototype.$prompt = Vue.prototype.$msgbox.prompt
Vue.prototype.$message = Message

Vue.config.productionTip = false


import enLocale from 'element-ui/lib/locale/lang/en'
import zhLocale from 'element-ui/lib/locale/lang/zh-CN'
import tcLocale from 'element-ui/lib/locale/lang/zh-TW'
import ElementLocale from 'element-ui/lib/locale'


const messages = {
  en: Object.assign(require('./common/en'),require('./locales/en.json'), enLocale),
  'zh-CN':Object.assign(require('./common/zh'),require('./locales/zh-cn.json'), zhLocale),
  tc:Object.assign(require('./common/tc'), tcLocale)
}
const i18n = new VueI18n({
    locale: localStorage.getItem("lang")==undefined?'zh-CN':localStorage.getItem("lang"),    // 语言标识
    //this.$i18n.locale // 通过切换locale的值来实现语言切换
    messages
})
ElementLocale.i18n((key, value) => i18n.t(key, value))
const vm = new Vue({
  router,
  store,
  i18n,
  data() {
    return {
      Hub: new Vue({}),
    }
  },

  render: h => h(App)
}).$mount('#app')
import * as custom from './assets/js/filters'
Object.keys(custom).forEach(key => {
  Vue.filter(key, custom[key])
})

Vue.mixin({
  computed: {
    // 定义图片上传地址
    uploadURL () {
      return this.$axios.defaults.baseURL + 'api/common/upload'
    }
  },
  methods: {
    te(arg) {
      const hasKey = this.$te(arg)
      if (hasKey) {
        const result = this.$t(arg)
        return result
      }
      return arg
    },
    // 得到上传请求头，用于图片上传
    getAuthHeaders () {
      return {
        token: `${sessionStorage.getItem('token') || ''}`
      }
    }
  },
});
export default vm;
